/**
 * Copyright (C) 2009 All Rights Reserved
 * @author sebastian chang
 * @brief practice
 */


#ifndef _H_MUTEX_LOCK_H_
#define _H_MUTEX_LOCK_H_

#include <pthread.h>
#include <errno.h>

#include "lock.h"

namespace trident {

/**
 * @brief the interface of all lock
 */
class mutex_lock_t : public lock_i
{
public:
    /**
     * @brief constructor
     */
    mutex_lock_t();

    /**
     * @brief destructor
     */
    ~mutex_lock_t();

    /**
     * @brief initialize
     */
    int init(void* arg_ = NULL);

    /**
     * @brief lock
     */
    int lock();

    /**
     * @brief unlock
     */
    int unlock();

    /**
     * @brief lock
     */
    int trylock();

    /**
     * @brief unlock
     * @param unsigned long timeout_ sets time out, which is millisecond
     */
    int timeWait(unsigned long timeout_);

private:

    pthread_mutex_t     _mutex;             ///< mutex lock
};


} // namespace trident

#endif // _H_MUTEX_LOCK_H_
